package com.foxzzz.binary.search;

public class Solution35 {
    public int searchInsert(int[] nums, int target) {
        return search(nums, target, 0, nums.length - 1);
    }

    private int search(int[] nums, int target, int low, int high) {
        while (low <= high) {
            int mid = (low + high) >> 1;
            if (nums[mid] == target) return mid;
            else if (target > nums[mid])
                low = mid + 1;
            else
                high = mid - 1;
        }
        return low;

    }

    public static void main(String[] args) {
        int result = new Solution35().searchInsert(new int[]{1, 3, 5, 6}, 0);
        System.out.println(result);
    }
}
